class Config:
    azimuthValues = ["90","180", "270"]
    shadingValues = ["100", "93", "85"]
    panelInverterCounts = ["11", "22", "30", "44"]
    initialPayments = ["0", "250", "1000", "2000", "5000"]
    annualIncreases = ["0","1","2","2.9","3.5"]
    genericProperties = {}
    def __init__(self,inputFile="config.txt"):
        self.genericProperties = setDefaultGenerics()
        with open(inputFile, 'r') as myFile:
            for line in myFile:
                line = line.strip().lower()
                if not line:
                    continue
                if line[0]=="#":
                    continue
                if line.startswith("azimuthvalues"):
                    self.azimuthValues = getObject(line)
                elif line.startswith("shadingvalues"):
                    self.shadingValues= getObject(line)
                elif line.startswith("panelinvertercounts"):
                    self.panelInverterCounts = getObject(line)
                elif line.startswith("systemsizes"):
                    self.systemSizes = getObject(line)
                elif line.startswith("designfactors"):
                    self.designFactors = getObject(line)
                elif line.startswith("annualincreases"):
                    self.annualIncreases = getObject(line)
                elif line.startswith("initialpayments"):
                    self.initialPayments = getObject(line)
                elif line.startswith("grossmarginvalues"):
                    self.grossMarginValues = getObject(line)
                else:
                    (key, sep, values) = line.partition(":")
                    if "," in values:
                        self.genericProperties[key] = getObject(line)
                    else:
                        self.genericProperties[key] = values.strip()
    def getProperty(self, key):
        return self.genericProperties[key]
    def hasProperty(self, key):
        return key.lower() in self.genericProperties
            

def getObject(line):
    strValues = line.split(":")[1].strip()
    values = [x.strip() for x in strValues.split(",")]
    ret = None
    if "=" in strValues:
        ret = {}
        for val in values:
            (key, value) = val.split("=")
            key = key.strip()
            value = value.strip()
            if ";" in value:
                value = [x.strip() for x in value.split(";")]
            if "->" in key:
                (key1, key2) = key.split("->")
                ret[key1, key2] = value
            else:
                ret[key] = value
    else:
        ret = []
        for val in values:
            ret.append(val)
    return ret

def setDefaultGenerics():
    props = {}
    props['cutility1']='291'
    props['euse1']='2000'
    props['euse2']='2000'
    props['euse3']='2000'
    props['euse4']='2000'
    props['euse7']='2000'
    props['euse6']='2000'
    props['euse5']='2000'
    props['euse9']='2000'
    props['euse8']='2000'
    props['euse12']='2000'
    props['euse11']='2000'
    props['euse10']='2000'
    props['cheight1']='500'
    props['clength1']='500'
    props['soiling']='2'
    props['usetou']='0'
    props['inoct1']='44'
    props['incent2615']='1'
    props['invid_a1']='917'
    props['inverterid']='917'
    props['presolarrate1']='4042'
    props['collectorid']='2352'
    props['username']='lwooley@completesolar.com'
    props['password']='solar123solar'
    props['customer']='helios'
    props['crate1']='4042'
    props['tilt1']='20'
    props['siteassessment']='0'
    return props
